<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="utf-8">
<meta name="viewport"
	content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
<meta name="format-detection"
	content="telephone=no,email=no,date=no,address=no">
<title></title>
<link rel="stylesheet" type="text/css" href="../css/aui.css" />
<style type="text/css">
.aui-list .aui-list-item i.aui-iconfont {
	-webkit-align-self: center;
	align-self: center;
	font-size: 18px;
}
</style>
</head>
<body>
	<div class="aui-searchbar" id="search">
		<div class="aui-searchbar-input aui-border-radius">
			<i class="aui-iconfont aui-icon-search"></i> <input type="search"
				placeholder="请输入合同编号" id="search-input">
			<div class="aui-searchbar-clear-btn">
				<i class="aui-iconfont aui-icon-close"></i>
			</div>
		</div>
		<div class="aui-searchbar-btn" tapmode>取消</div>
	</div>
	<section class="aui-content">
		<ul class="aui-list aui-media-list" id="nice-articles">
		</ul>
	</section>
	<section class="aui-content" id="list"></section>
	<div style="width:100%;height:2.5rem;"></div>
	
	
	<div class="loading" id="loading" style="display: none;">
	    <ul >
	      <center ><img src="${pageContext.request.contextPath}/img/rotate.gif" height="25" width="25"></center>
	      <li style="color:#000; text-align:center; ">正在加载....</li>
	    </ul>
	</div>
	<div class="loading" id="loading_none" style="display: none;">
	    <ul>
	      <li style="color:#000; text-align:center">没有更多了....</li>
	    </ul>
	</div>
</body>
<script  type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript">
	
	//当前初始页
	var pageNumber = 1;
	//每页显示多少条
	var pageSize=20;
	var countSize = 0;
	$(function(){
		getPage(pageNumber,pageSize);
	})
	
	//根据param来选择当前页
	//初始方法
	/*$(function() {
		var total;
		getPage(pageNumber, pageSize);
		if(total==0){
       		console.log(total);
			$("#loading_none").show();
			$("#loading").hide();
		}else{
			if(total>1){
				$(window).scroll(function(){
   					if($(document).scrollTop()+10 >= $(document).height()-$(window).height()){
   						$("#loading").show();
   						pageNumber = pageNumber+1;
   						if(pageNumber <= total){
   							getPage(pageNumber, pageSize);
   							console.log("begin"+pageNumber);
   						}else {
   							$("#loading").hide();
   							$("#loading_none").show();
   						}
   					}
   				});//滚动条事件
			}else{
				$("#loading").hide();
				$("#loading_none").show();
			}
		}
	});*/
	
	
	$("#search-input").change(function(){
	pageNumber = 1;
	pageSize=20;
	countSize = 0;
	getPage(pageNumber, pageSize);}
	);
	
	function getPage(pageNumber, pageSize) {
		var contractNum = $("#search-input").val();
		
		$.ajax({
					url : '${pageContext.request.contextPath}/appcrm/appContractList.do?pageNo='
							+ pageNumber + '&pageSize=' + pageSize + "&contractNum=" + contractNum,
					type : "POST",
					dataType : "json",
					beforeSend:function(){
             			$("#loading").show();
             			$("#loading_none").hide();
       				},
					success : function(data) {
					//total=data.pageInfo.totalpages;
					console.log(data.pageInfo.list);
						var html = "";
						if (data.code == "0") {
							if (typeof (data.pageInfo.list) != null && data.pageInfo.list != "") {
								var da = data.pageInfo.list;
								var customer = data.customer;
								var html = "";
								for (var i = 0; i < da.length; i++) {
									html += '<li class="aui-list-item aui-list-item-middle" tapmode onclick="openDetailed(\''
											+ da[i].contractId
											+ '\')"><div class="aui-media-list-item-inner"><div class="aui-list-item-inner aui-list-item-arrow"><div class="aui-list-item-text">';
									if (da[i].contractName != null
											&& da[i].contractName != "") {
										html += '<div class="aui-list-item-title aui-font-size-14">'
												+ da[i].contractName + '</div>';
									} else {
										html += '<div class="aui-list-item-title aui-font-size-14">滨海基金项目合同</div>';
									}
									if (da[i].createDate != null
											&& da[i].createDate != "") {
										html += '<div class="aui-list-item-right">'
												+ toDate(da[i].createDate)
												+ '</div>'
									} else {
										html += '<div class="aui-list-item-right"></div>'
									}
									html += '</div><div class="aui-list-item-text">'
									if (da[i].contractNum != null
											&& da[i].contractNum != "") {
										html += da[i].contractNum
									}
									html += '<div class="aui-list-item-right">'
									for (var j = 0; j < customer.length; j++) {
										if (da[i].customerId == customer[j].customerId) {
											html += customer[j].customerName
										}
									}
									html += "</div></div></div></div></li>";
								}
								
									if(pageNumber==1){
		            					$("#nice-articles").empty().append(html);
		            				}else{
		            					$("#nice-articles").append(html);
		            				}
								
								//countSize = da.total;
								//复制总记录数
							} else {
								$("#list").html("<div style='width:100%;text-align:center;color:#999;padding:10px 0;'>暂无数据！</div>");
							}
							$("#loading").hide();
							$("#nice-articles").html(html);

						}
					}
				});
	}
	
		//打开详细
		function openDetailed(id) {
			window.location.href="${pageContext.request.contextPath}/wap/public_work.do?path=frame_contract_detailed&id="+id;
		}

	function toDate(data) {
		var date = new Date(data);
		var y = date.getFullYear();
		var m = date.getMonth() + 1;
		m = m < 10 ? '0' + m : m;
		var d = date.getDate();
		d = d < 10 ? ('0' + d) : d;
		return y + '-' + m + '-' + d;
	}
</script>
</html>